import Vue from 'vue'
import Vuex from 'vuex'

import { setItem, getItem } from '../utils/storage'

Vue.use(Vuex)

// 声明一个常量能够减少错误
const KeyToken = 'TKON NAME'
export default new Vuex.Store({
  state: {
    user: getItem(KeyToken)
  },
  mutations: {
    setUser (state, data) {
      state.user = data
      // 存储到 localStorage 里面备份
      setItem(KeyToken, state.user)
    }
  },
  actions: {},
  modules: {}
})
